package Graphique;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.rmi.RemoteException;
import java.util.ArrayList;

import javax.swing.*;

import Serveur.InterfaceClient;
import Serveur.Twouit;
import Serveur.Utilisateur;

public class Affiche extends JFrame{
	private static final long serialVersionUID = 1L;
	private JLabel intro = new JLabel();
	private JComboBox<String> jComboBox = new JComboBox<String>();
	
	public Affiche(String titre, ArrayList<?> l, String type) throws RemoteException{
		
		super(titre);
		this.setSize(250, 250);
		intro.setText(titre);
		getContentPane().setLayout(new BorderLayout());
		
		DefaultComboBoxModel<String>  mdc = new DefaultComboBoxModel<String>();
		jComboBox.setModel(mdc);
		
		getContentPane().setLayout(new GridLayout(1,3));
		JPanel jp = new JPanel();
		jp.add(intro);
		jp.add(jComboBox);
		jp.setLayout(new GridLayout(l.size(), 1));
		
		//Affiche un twouit
		if(type.equals("twouit")) {
			for (int i = 0; i < l.size(); i++){
				Twouit t = (Twouit) l.get(i);
				jComboBox.addItem(t.toString());
			}
		//Affiche les fauxlover d'un user
		} else if(type.equals("fauxlover")) {
            for (int i = 0; i < l.size(); i++) {
                System.out.println(i);
                InterfaceClient client = (InterfaceClient) l.get(i);
                Utilisateur user = client.getUtilisateur();
                jComboBox.addItem(user.getLogin());
            }
		}
		//Affiche le autres demandes
		else {
			for (int i = 0; i < l.size(); i++) {
				jComboBox.addItem(l.get(i).toString());
			}
		}
		this.add(jp);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		this.pack();
	}
}
